package cn.renxuan.querys;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.renxuan.entity.TB_AdministrativeDivision;
import cn.renxuan.repository.DynamicParameters;

/*
 * 行政区划查询类
 */
public class AdministrativeDivisionQuery extends BaseQueryWithPrimaryKey<TB_AdministrativeDivision, Long> {
    private String defaultTableAlias = "ad";

    private List<String> codeList;

    public List<String> getCodeList() {
        return codeList;
    }

    public void setCodeList(List<String> codeList) {
        this.codeList = codeList;
    }

    @Override
    public Map<String, DynamicParameters> getQuerySql() {
        Map<String, DynamicParameters> querySqls = new HashMap<String, DynamicParameters>();
        StringBuilder sbsql = new StringBuilder();
        DynamicParameters parameters = new DynamicParameters();

        if (!isContainDeleted) {
            sbsql.append(String.format(" AND %s.IsDeleted = 0 ", defaultTableAlias));
        }

        // 主键过滤
        if (idList != null && idList.size() > 0) {
            sbsql.append(String.format(" and %s.Id in (%s) ", defaultTableAlias,
                    getCollectionSymbol(idList, parameters, "idList")));
            // parameters.add("idList", idList);
        }

        if (codeList != null && codeList.size() > 0) {
            sbsql.append(String.format(" and %s.Code in (%s) ", defaultTableAlias,
                    getCollectionSymbol(codeList, parameters, "codeList")));
            // parameters.add("codeList", codeList);
        }

        querySqls.put(sbsql.toString(), parameters);
        return querySqls;
    }
}
